package dyyx.demo;
import java.util.Date;

import org.h2.mvstore.Cursor;
import org.h2.mvstore.MVMap;
import org.h2.mvstore.MVStore;

import dyyx.util.CommUtil;

public class MVStoreScanTest {

	public static void main(String[] args) throws Exception {
		System.out.println("hello,MVStoreScanTest,"+new Date());
		
		String home = CommUtil.getUserHome();
		System.out.println("home="+home);
		String fileName = home+"/h2/001.data";
		
		//  java.lang.IllegalArgumentException: Directory does not exist: nio:/Users/dugang/h2 [1.4.200/0]
		MVStore s = MVStore.open(fileName);
		

		MVMap<Integer, String> map = s.openMap("data");

		long start = System.currentTimeMillis();
		
		Integer min = map.firstKey();
		
		System.out.println("firstKey="+min);
		
		Cursor<Integer, String> c = map.cursor(min);
		
	
		int index = 0;
		Integer key = null;
		
		long batchStartTime = start;
		long batchStartTimeOld = 0;
		long batchTime = 0;
		
		
		
		while(c.hasNext()){
			key = c.next();
			index++;
			if(index >0 && index %1000000 ==0){
				batchStartTimeOld = batchStartTime;
				batchStartTime = System.currentTimeMillis();
				batchTime = batchStartTime - batchStartTimeOld;
				System.out.println(index+","+batchTime+",key="+key+","+map.get(key));
			}
				
		}
		
		
		long end = System.currentTimeMillis();
		long time = end - start;
		
		System.out.println("time="+time);
		
		System.out.println("lastKey="+key);

		

		start = System.currentTimeMillis();
		s.close();
		end = System.currentTimeMillis();
		time = end - start;
		System.out.println("time2="+time);



	}
}
